package com.aisile.teacher.controller;


import com.aisile.model.teacher.dtos.TeacherAndStudentDto;
import com.aisile.model.teacher.dtos.TeacherListDto;
import com.aisile.model.base.vos.R;
import com.aisile.teacher.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther:yry
 * @Date:2024/6/20 0020
 * @VERSON:1.0
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @PostMapping("/save")
    public R saveTeacherAndStudent(@RequestBody TeacherAndStudentDto dto) {
        return teacherService.saveTeacherAndStudents(dto);
    }

    @PostMapping("/update")
    public R updateTeacherAndStudent(@RequestBody TeacherAndStudentDto dto) {
        return teacherService.udpateTeacherAndStudents(dto);
    }

    @PostMapping("/list")
    public R findList(@RequestBody TeacherListDto dto) {
        return teacherService.findList(dto);
    }

    @DeleteMapping("/del/{id}")
    public R deleteTeacher(@PathVariable("id") Integer id) {
        return teacherService.deleteTeacherAndStudent(id);
    }

    // 批量删除  DeleteMapping 不能传递对象  只能url方式传值
    @PostMapping("/dels")
    public R deleteTeachers(@RequestBody List<Integer> ids){
        return teacherService.deleteTeacherByIds(ids);
    }


    @GetMapping("/one/{id}")
    public R findTeacherById(@PathVariable("id") Integer id){
        return teacherService.findTeacherById(id);
    }

}
